package com.example.demo;

import com.example.demo.repository.entity.UserEntity;
import com.example.demo.service.UserService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

import javax.annotation.PostConstruct;

/**
 * 动态数据源测试项目
 *
 * @author wuhong-016
 * @version v1.0.0
 * @time: 2021/10/16 10:18
 */
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@MapperScan(value = {"com.example.demo.repository.mapper"})
public class DynamicMybatisApplication {

    @Autowired
    private UserService userService;

    public static void main(String[] args) {
        SpringApplication.run(DynamicMybatisApplication.class, args);
    }

    @PostConstruct
    public void doAfterStarted(){
        UserEntity user1 = userService.selectFromPrimary();
        UserEntity user2 = userService.selectFromSecond();

        System.out.println(user1);
        System.out.println(user2);
    }

}
